package com.bupt.liutong.admin.shop.dao;

import java.util.List;

import com.bupt.liutong.admin.core.base.Ibatis;
import com.bupt.liutong.admin.core.base.Photo;
import com.bupt.liutong.admin.core.base.PhotoDao;
import com.bupt.liutong.admin.shop.dto.ProdPhoto;

public class ProdPhotoDao implements PhotoDao {

	private Ibatis ibatis;

	@SuppressWarnings("unchecked")
	public List<ProdPhoto> getProdPhotosByProdId(Integer id) {
		return (List<ProdPhoto>) ibatis.queryForList(
				"shop_prod_photo.getProdPhotosByProdId", id);
	}

	public ProdPhoto getProdPhotoById(Integer id) {
		return (ProdPhoto) ibatis.queryForObject(
				"shop_prod_photo.getProdPhotoById", id);
	}

	public void insertProdPhoto(ProdPhoto prodPhoto) {
		ibatis.insert("shop_prod_photo.insertProdPhoto", prodPhoto);
	}

	public void updateProdPhoto(ProdPhoto prodPhoto) {
		ibatis.update("shop_prod_photo.updateProdPhoto", prodPhoto);
	}

	public void deleteProdPhoto(Integer id) {
		ibatis.delete("shop_prod_photo.deleteProdPhoto", id);
	}

	public void deleteProdPhotoByProdId(Integer prodId) {
		ibatis.delete("shop_prod_photo.deleteProdPhotoByProdId", prodId);
	}

	public void setIbatis(Ibatis ibatis) {
		this.ibatis = ibatis;
	}

	
	public Photo deletePhoto(Integer id) {
		ProdPhoto prodPhoto = this.getProdPhotoById(id);
		this.deleteProdPhoto(id);
		return prodPhoto;
	}

	
	public void insertPhoto(Photo uploadDto) {
		this.insertProdPhoto((ProdPhoto) uploadDto);
	}

	
	public void updatePhoto(Photo photo) {
		this.updateProdPhoto((ProdPhoto) photo);
	}
}
